deploy: Clean up bootserial assignment function
authorColin Walters <walters@verbum.org>
Thu, 12 Apr 2018 16:43:39 +0000 (12:43 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 13 Apr 2018 15:26:28 +0000 (15:26 +0000)
The reason we were returning a hashtable is a bit lost to history,
there's no reason to do so now anyways.  Also port to declare-and-initialize
style and add more comments.

Closes: #1538
Approved by: jlebon

src/libostree/ostree-sysroot-deploy.c

index b593ce38f8768a800de802df2ef86be99dc54ab9..d3540c8d9b1c9b249304eca955e4120399a12897 100644 (file)
@@ -1874,26 +1874,26 @@ swap_bootloader (OstreeSysroot  *sysroot,
   return TRUE;
 }
 
-static GHashTable *
+/* Deployments may share boot checksums; the bootserial indexes them
+ * per-bootchecksum. It's used by the symbolic links after the bootloader.
+ */
+static void
 assign_bootserials (GPtrArray   *deployments)
 {
-  guint i;
-  GHashTable *ret =
+  g_autoptr(GHashTable) serials =
     g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
 
-  for (i = 0; i < deployments->len; i++)
+  for (guint i = 0; i < deployments->len; i++)
     {
       OstreeDeployment *deployment = deployments->pdata[i];
       const char *bootcsum = ostree_deployment_get_bootcsum (deployment);
-      guint count;
-
-      count = GPOINTER_TO_UINT (g_hash_table_lookup (ret, bootcsum));
-      g_hash_table_replace (ret, (char*) bootcsum,
+      /* Note that not-found maps to NULL which converts to zero */
+      guint count = GPOINTER_TO_UINT (g_hash_table_lookup (serials, bootcsum));
+      g_hash_table_replace (serials, (char*) bootcsum,
                             GUINT_TO_POINTER (count + 1));
 
       ostree_deployment_set_bootserial (deployment, count);
     }
-  return ret;
 }
 
 /* OSTree implements a special optimization where we want to avoid touching
@@ -2146,7 +2146,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
 
   /* Assign a bootserial to each new deployment.
    */
-  g_hash_table_unref (assign_bootserials (new_deployments));
+  assign_bootserials (new_deployments);
 
   /* Determine whether or not we need to touch the bootloader
    * configuration.  If we have an equal number of deployments with